package com.wingy.mybroadcastinjava;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class SMSReceiverActivity extends BroadcastReceiver {

    private static final String Tag = "onReceive";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(Tag, "onReceive-->running");
        Bundle bundle = intent.getExtras();
        Object[] myObject = (Object[]) bundle.get("pdus");
        SmsMessage[] messages = new SmsMessage[myObject.length];
        System.out.println(messages.length);
        for(int i = 0; i<myObject.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) myObject[i]);
            System.out.println(messages[i].getDisplayMessageBody());
        }
    }
}
